package com.kompas.bola.application.adapter;

import java.util.List;

import com.kompas.bola.application.R;
import com.kompas.bola.application.WebActivity;
import com.kompas.bola.application.db.CrudHelper;
import com.kompas.bola.application.model.Content;
import com.kompas.bola.application.utils.Constants;
import com.kompas.bola.application.utils.ImageLoader;
import com.kompas.bola.application.utils.Utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ListBookmarkAdapter extends BaseAdapter {
	/** =========================================================================== */  
	private String status;
	private Activity activity;
	private List<Content> data;
    private ImageLoader imageLoader;     
	private LinearLayout imageViewLayout;
	private boolean _sublist 			= false;
	private static LayoutInflater inflater = null;
	/** =========================================================================== */   
	public ListBookmarkAdapter(Activity a, List<Content> d) {
		activity 						= a;
		data 							= d;
		inflater 						= (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader						= new ImageLoader(activity.getApplicationContext());
        setList(data);
	}
	/** =========================================================================== */
	public void setList(List<Content> list){
		this.data						= list;
	}
	/** =========================================================================== */
	public List<Content> isList(){
		return this.data;
	}
	/** =========================================================================== */
	public void setSublist(boolean paramBoolean){
	    this._sublist 					= paramBoolean;
	}
	/** =========================================================================== */  
	public boolean isSublist(){
	    return this._sublist;
	}
	/** =========================================================================== */   
	public int getCount() {
		return data.size();
	}
	/** =========================================================================== */   
	public Object getItem(int position) {
		return position;
	}
	/** =========================================================================== */   
	public long getItemId(int position) {
		return position;
	}
	/** =========================================================================== */   
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;

        Content bola				= new Content();
        bola 						= data.get(position); 
      	
      	CrudHelper db				= new CrudHelper(activity);
      	status						= db.getStatusByGuid(bola.getKEY_GUID());
        
        
		vi 							= inflater.inflate(R.layout.list_row_bookmark, null);	

	    imageViewLayout 			= ((LinearLayout)vi.findViewById(R.id.thumbnail));
		TextView guid				= (TextView) vi.findViewById(R.id.guid); // guid
		TextView title 				= (TextView) vi.findViewById(R.id.title); // title
		ImageView  thumb_image 		= (ImageView) vi.findViewById(R.id.list_image); // thumb image

		guid.setText(bola.getKEY_GUID());
		title.setText(bola.getKEY_TITLE());
		      	
      	if(status.equalsIgnoreCase(Constants.AFTER_READ)){
      		title.setTextColor(Color.GRAY);
      	}
		
		if(!bola.getKEY_PHOTO_URL().equalsIgnoreCase(Constants.EMPTY)){
	        imageViewLayout.setVisibility(View.VISIBLE);
			imageLoader.DisplayImage(bola.getKEY_PHOTO_URL(),thumb_image,Constants.SCALETYPE_CENTER_CROP);				
		}else{
			imageViewLayout.setVisibility(View.GONE);
			imageLoader.clearCache();
		}
		
		return vi;
	}
	/** =========================================================================== */
}
